import { Component, OnInit, Input } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-inquiryinfo-component',
  templateUrl: './inquiryinfo-component.component.html',
  styleUrls: ['./inquiryinfo-component.component.less']
})
export class InquiryInfoComponent implements OnInit {

  validateForm: FormGroup;
  @Input() isregister: boolean;

  inputValue: string;
  options = [];

  constructor(private fb: FormBuilder) {
  }

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      stock: [{
        value: '中国平安',
        disabled: !this.isregister
      }, [Validators.required]],
      proportion_1: [null],
      proportion_2: [null],
      proportion_3: [null],
      proportion_4: [null],
      proportion_5: [null],
      proportion_6: [null],
      inquirymodal: [null, [Validators.required]],
      origin: [null],
      sort: [null]
    });
  }

  submitForm(): void {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
  }

  onChange(value: string): void {
    this.options = new Array(this.getRandomInt(15, 5)).join('.').split('.')
      .map((item, idx) => ({
        value,
        category: `${value}${idx}`,
        count: this.getRandomInt(200, 100),
      }));
  }

  getRandomInt(max: number, min: number = 0): number {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
}
